package com.liuwei.msmall.search.controller;

import com.liuwei.msmall.search.service.EsSearchService;
import com.liuwei.msmall.search.vo.SearchParmsVo;
import com.liuwei.msmall.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Classname SearchController
 * @Description TODO
 * @Date 2020/6/18 20:47
 * @Created by 刘
 */
@Controller
public class SearchController {

    @Autowired
    EsSearchService esSearchService;



    @GetMapping("/list.html")
    public String list(SearchParmsVo parmsVo, Model model, HttpServletRequest request){

        SearchRespVo respVos =esSearchService.search(parmsVo);
        //如果没查到数据就不用放空对象到请求域中
        if (!CollectionUtils.isEmpty(respVos.getSkuModels())){
            model.addAttribute("result",respVos);
        }
        System.out.println(respVos);
        //将数据放在请求域中
        return "list";
    }


}
